home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0" encoding="utf-8"?>
- <!-- ===========================================================
- Category: XSLT
- Sub-category: xsl:sort
- Author: David Silverlight
- HeadGeek@xmlpitstop.com
- Created: 2001-05-16
- Description:-
- This stylesheet demonstrates the use of xsl:sort by sorting
- Employee Information with Multi-part Keys.
- =============================================================== -->
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
- <xsl:output method="html" />
-
- <xsl:template match="/">
- <html>
- <head>
- <title>Stylesheet Example</title>
- <style type="text/css"><![CDATA[
- H1 {COLOR: red; FONT-FAMILY: Arial; FONT-SIZE: 14pt;}
- H2 {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
- .head {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 14pt;}
- .subhead {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
- .text {COLOR: black; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
- TH {COLOR: white; FONT-FAMILY: Arial; background-color: darkblue;}
- TD {COLOR: darkblue; FONT-FAMILY: Arial}
- TR { background-color: beige; }
- BODY { background-color: beige; }
- ]]></style>
- </head>
- <body>
- <xsl:apply-templates />
- </body>
- </html>
- </xsl:template>
-
- <xsl:template match="employees">
- <h1>Sorting Employees by StartDate then by Hourly Rate within Department</h1>
- <table border="1">
- <tr>
- <th>Name</th>
- <th>Department</th>
- <th>Hourly Rate</th>
- <th>Start Date</th>
- <th>Primary Language</th>
- </tr>
- <xsl:for-each select="employee">
- <xsl:sort order="ascending" select="department" />
- <xsl:sort order="ascending" select="hourlyrate" data-type="number" />
- <tr>
- <td>
- <xsl:value-of select="employeename" />
- </td>
- <td>
- <xsl:value-of select="department" />
- </td>
- <td>
- <xsl:value-of select="hourlyrate" />
- </td>
- <td>
- <xsl:value-of select="startdate" />
- </td>
- <td>
- <xsl:value-of select="primarylanguage" />
- </td>
- </tr>
- </xsl:for-each>
- </table>
- <br />
- <br />
- <h1>Sorting Employees by StartDate then by Hourly Rate within Department(descending)</h1>
- <table border="1">
- <tr>
- <th>Name</th>
- <th>Department</th>
- <th>Hourly Rate</th>
- <th>Start Date</th>
- <th>Primary Language</th>
- </tr>
- <xsl:for-each select="employee">
- <xsl:sort order="ascending" select="department" />
- <xsl:sort order="descending" select="hourlyrate" data-type="number" />
- <tr>
- <td>
- <xsl:value-of select="employeename" />
- </td>
- <td>
- <xsl:value-of select="department" />
- </td>
- <td>
- <xsl:value-of select="hourlyrate" />
- </td>
- <td>
- <xsl:value-of select="startdate" />
- </td>
- <td>
- <xsl:value-of select="primarylanguage" />
- </td>
- </tr>
- </xsl:for-each>
- </table>
- </xsl:template>
- </xsl:stylesheet>